import { login } from '@/api/user'

const state = {
  token: localStorage.getItem('token')
}
const mutations = {
  setToken(state, token) {
    state.token = token
    // 备份持久数据
    localStorage.setItem('token', token)
  }
}
const actions = {
  // 登录actions调用时，应该传入用户填写的表单，
  async login(store, loginForm) {
    const res = await login(loginForm)
    store.commit('setToken', res)
    console.log('actions正在调用')
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
